<?php

function hexToStr( $hex )
{
    $string='';
    for ($i=0; $i < strlen($hex)-1; $i+=2)
    {
        $string .= chr(hexdec($hex[$i].$hex[$i+1]));
    }
    return $string;
}

function strToHex( $string )
{
    $hex='';
    for ($i=0; $i < strlen($string); $i++)
    {
        $hex .= dechex(ord($string[$i]));
    }
    return $hex;
}

function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

function getMonthName( $monthNumber )
{
    global $langStr;
    switch($monthNumber)
    {
    case 1: return isEnglish() ? "January" : "Január";
    case 2: return isEnglish() ? "February" : "Február";        
    case 3: return isEnglish() ? "March" : "Marec";
    case 4: return isEnglish() ? "April" : "Apríl";
    case 5: return isEnglish() ? "May" : "Máj";
    case 6: return isEnglish() ? "June" : "Jún";
    case 7: return isEnglish() ? "July" : "Júl";
    case 8: return isEnglish() ? "August" : "August";
    case 9: return isEnglish() ? "September" : "September";
    case 10: return isEnglish() ? "October" : "Október";
    case 11: return isEnglish() ? "November" : "November";
    case 12: return isEnglish() ? "December" : "December";
    default: return "";
    }
}

function isEnglish()
{
    if (isset( $_SESSION['language'] ) && $_SESSION['language'] == 1)
    {
        return true;
    }
    
    return false;
}

function showError( $errorStr )
{
    if (isset( $_SESSION[ 'infoData' ] ))
        unset( $_SESSION[ 'infoData' ] );
        
    $_SESSION[ 'errorData' ] = $errorStr;
    header("location: ./../index.php?siteName=mainsites/errorinfo.php"); 
}

function showInfo( $infoStr )
{
    if (isset( $_SESSION[ 'errorData' ] ))
        unset( $_SESSION[ 'errorData' ] );
    
    $_SESSION[ 'infoData' ] = $infoStr;
    header("location: ./../index.php?siteName=mainsites/errorinfo.php");
}

function redirectToMainSite( $mainSiteName )
{
     $redirectStr = "location: ./../index.php?siteName=mainsites/" . $mainSiteName;
     header( $redirectStr );
}

?>
